package user

import (
	"API/client"
	"API/request"
	"API/response"
	"github.com/gin-gonic/gin"
	user "user_server/proto"
)

// SignInHandler 处理用户签到API请求
func SignInHandler(c *gin.Context) {
	userId := c.GetUint("userId")
	res, err := client.UserSignIn(c, &user.SignInRequest{
		UserId: int32(userId),
	})
	// 添加双重错误检查
	if err != nil {
		response.CurrencyErrResponse(c, 500, err.Error())
		return
	}
	response.CurrencySuccessResponse(c, res.Message, nil)
}

// RetroactiveSignHandler 处理用户补签API请求
func RetroactiveSignHandler(c *gin.Context) {
	var req request.RetroactiveSignRequest
	if err := c.ShouldBind(&req); err != nil {
		response.CurrencyErrResponse(c, 400, err.Error())
		return
	}
	userId := c.GetUint("userId")
	res, err := client.UserRetroactiveSign(c, &user.RetroactiveSignRequest{
		UserId: int32(userId),
		Date:   req.Date,
	})
	if err != nil {
		response.CurrencyErrResponse(c, 500, err.Error())
		return
	}
	response.CurrencySuccessResponse(c, res.Message, nil)
}
